package org.example.mulitithreading.read_write_lock;

import java.util.concurrent.locks.ReentrantReadWriteLock;

public class Demo2 {
    public static void main(String[] args) {
        // 可重入读写锁对象
        ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
        // 锁定读锁
        lock.readLock().lock();
        System.out.println("read读取");
        // 错误的锁降级
        // 锁定写锁
        lock.writeLock().lock();
        System.out.println("飞飞");
        // 解锁
        lock.readLock().unlock();
        lock.writeLock().unlock();
    }
}
